#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<LL> nums(n + 1);
  vector<LL> suffixSum(n + 2);       // 后缀和
  vector<LL> suffixSquareSum(n + 2); // 后缀平方和

  for (int i = 1; i <= n; i++) {
    cin >> nums[i];
  }

  // 计算后缀和与后缀平方和
  for (int i = n; i >= 1; i--) {
    suffixSum[i] = (suffixSum[i + 1] + nums[i]) % mod;
    suffixSquareSum[i] = (suffixSquareSum[i + 1] + nums[i] * nums[i]) % mod;
  }

  LL result = 0;
  for (int i = 1; i <= n; i++) {
    LL square = nums[i] * nums[i] % mod;
    result = (result + (n - i) * square) % mod;
    result = (result + 2LL * nums[i] * suffixSum[i + 1]) % mod;
    result = (result + suffixSquareSum[i + 1]) % mod;
  }

  cout << result;
  return 0;
}